package com.shujia.city.dwd

import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession}

object DwdGsjRegLegrepreMskDay extends SparkTool {
  /**
   * 在run函数中写数据处理的逻辑
   */
  override def run(spark: SparkSession, ds: String): Unit = {
    import spark.implicits._
    import org.apache.spark.sql.functions._

    //1、读取数据
    val legrepre: Dataset[Row] = spark
      .table("ods.ods_t_gsj_reg_legrepre")
      .where($"ds" === ds)

    //2、处理数据
    val resultDF: DataFrame = legrepre.select(
      upper(md5(concat($"id", expr("'shujia'")))) as "id", //身份证号脱敏处理
      regexp_replace($"position", "\"", "") as "position",
      upper(md5(concat($"tel", expr("'shujia'")))) as "tel",
      regexp_replace($"appounit", "\"", "") as "appounit",
      regexp_replace($"accdside", "\"", "") as "accdside",
      regexp_replace($"posbrmode", "\"", "") as "posbrmode",
      $"offhfrom",
      $"offhto",
      $"stufftype"
    )

    //将数据保存到hive表中
    saveToTable(spark, resultDF, "dwd.dwd_gsj_reg_legrepre_msk_d", ds)

  }
}
